<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <!-- 
            思路：先序遍历二叉搜索树，判断每个节点是否处于[low,hight]
            如果当前节点小于low，说明其左子树肯定不符合，递归遍历其右子树
            如果当前节点大于high，说明右子树肯定不符合，递归遍历其左子树
            如果处于区间内部，那么继续遍历其左右子树即可

         -->
        <script>
            var trimBST = function (root, low, high) {
                if (!root) return null
                if (root.val < low) {
                    return trimBST(root.right, low, high)
                }
                if (root.val > high) {
                    return trimBST(root.left, low, high)
                }
                //如果满足条件，保留根节点，递归其左右子树即可
                root.left = trimBST(root.left, low, high)
                root.right = trimBST(root.right, low, high)
                return root
            }
        </script>
    </body>
</html>
